import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ShiQifei
 * @date 2021/3/23 16:09
 */
public class AQS  {



    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
//        CountDownLatch count = new CountDownLatch(10);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 10, 1000L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(3));
        for(int i= 0 ; i <= 1; i++) {
            pool.execute(()->{
                lock.lock();
                System.out.println(Thread.currentThread().getName() + " 线程执行中...");
                System.out.println(Thread.currentThread().getName() + " 线程执行完成!");
                Thread.currentThread().interrupt();
                if(Thread.currentThread().isInterrupted()) {
                    System.out.println("hahah, 我还可以做事情");
                }

                try{
                    System.out.println("尝试sleep");
                    Thread.sleep(2000L);
                } catch (InterruptedException e) {
                    System.out.println("不好, 出问题了");
                    e.printStackTrace();
                     System.out.println(Thread.currentThread().isInterrupted());
                    return;
                }
                System.out.println("释放锁");
                lock.unlock();
//                count.countDown();
            });
        }

        pool.shutdown();


    }
}
